package cn.fsw.pethome.base.service.impl;

import cn.fsw.pethome.base.mapper.BaseMapper;
import cn.fsw.pethome.base.query.Page;
import cn.fsw.pethome.base.service.IBaseService;
import cn.fsw.pethome.org.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> selectAll() {
        return baseMapper.selectAll();
    }

    @Override
    public T selectById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);

    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public PageList<T> pageSelevtAll(Page query) {
        PageList<T> result = new PageList<>();
        result.setTotal(baseMapper.count(query));
        result.setData(baseMapper.pageSelevtAll(query));

        return result;
    }

}
